// Copyright 2025 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Code generated by sidekick. DO NOT EDIT.

#[allow(unused_imports)]
use super::*;

#[doc(hidden)]
impl serde::ser::Serialize for super::TroubleshootIamPolicyRequest {
    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
    where
        S: serde::ser::Serializer,
    {
        use serde::ser::SerializeMap;
        #[allow(unused_imports)]
        use std::option::Option::Some;
        let mut state = serializer.serialize_map(std::option::Option::None)?;
        if self.access_tuple.is_some() {
            state.serialize_entry("accessTuple", &self.access_tuple)?;
        }
        if !self._unknown_fields.is_empty() {
            for (key, value) in self._unknown_fields.iter() {
                state.serialize_entry(key, &value)?;
            }
        }
        state.end()
    }
}

#[doc(hidden)]
impl serde::ser::Serialize for super::TroubleshootIamPolicyResponse {
    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
    where
        S: serde::ser::Serializer,
    {
        use serde::ser::SerializeMap;
        #[allow(unused_imports)]
        use std::option::Option::Some;
        let mut state = serializer.serialize_map(std::option::Option::None)?;
        if !wkt::internal::is_default(&self.overall_access_state) {
            state.serialize_entry("overallAccessState", &self.overall_access_state)?;
        }
        if self.access_tuple.is_some() {
            state.serialize_entry("accessTuple", &self.access_tuple)?;
        }
        if self.allow_policy_explanation.is_some() {
            state.serialize_entry("allowPolicyExplanation", &self.allow_policy_explanation)?;
        }
        if self.deny_policy_explanation.is_some() {
            state.serialize_entry("denyPolicyExplanation", &self.deny_policy_explanation)?;
        }
        if !self._unknown_fields.is_empty() {
            for (key, value) in self._unknown_fields.iter() {
                state.serialize_entry(key, &value)?;
            }
        }
        state.end()
    }
}

#[doc(hidden)]
impl serde::ser::Serialize for super::AccessTuple {
    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
    where
        S: serde::ser::Serializer,
    {
        use serde::ser::SerializeMap;
        #[allow(unused_imports)]
        use std::option::Option::Some;
        let mut state = serializer.serialize_map(std::option::Option::None)?;
        if !self.principal.is_empty() {
            state.serialize_entry("principal", &self.principal)?;
        }
        if !self.full_resource_name.is_empty() {
            state.serialize_entry("fullResourceName", &self.full_resource_name)?;
        }
        if !self.permission.is_empty() {
            state.serialize_entry("permission", &self.permission)?;
        }
        if !self.permission_fqdn.is_empty() {
            state.serialize_entry("permissionFqdn", &self.permission_fqdn)?;
        }
        if self.condition_context.is_some() {
            state.serialize_entry("conditionContext", &self.condition_context)?;
        }
        if !self._unknown_fields.is_empty() {
            for (key, value) in self._unknown_fields.iter() {
                state.serialize_entry(key, &value)?;
            }
        }
        state.end()
    }
}

#[doc(hidden)]
impl serde::ser::Serialize for super::ConditionContext {
    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
    where
        S: serde::ser::Serializer,
    {
        use serde::ser::SerializeMap;
        #[allow(unused_imports)]
        use std::option::Option::Some;
        let mut state = serializer.serialize_map(std::option::Option::None)?;
        if self.resource.is_some() {
            state.serialize_entry("resource", &self.resource)?;
        }
        if self.destination.is_some() {
            state.serialize_entry("destination", &self.destination)?;
        }
        if self.request.is_some() {
            state.serialize_entry("request", &self.request)?;
        }
        if !self.effective_tags.is_empty() {
            state.serialize_entry("effectiveTags", &self.effective_tags)?;
        }
        if !self._unknown_fields.is_empty() {
            for (key, value) in self._unknown_fields.iter() {
                state.serialize_entry(key, &value)?;
            }
        }
        state.end()
    }
}

#[doc(hidden)]
impl serde::ser::Serialize for super::condition_context::Resource {
    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
    where
        S: serde::ser::Serializer,
    {
        use serde::ser::SerializeMap;
        #[allow(unused_imports)]
        use std::option::Option::Some;
        let mut state = serializer.serialize_map(std::option::Option::None)?;
        if !self.service.is_empty() {
            state.serialize_entry("service", &self.service)?;
        }
        if !self.name.is_empty() {
            state.serialize_entry("name", &self.name)?;
        }
        if !self.r#type.is_empty() {
            state.serialize_entry("type", &self.r#type)?;
        }
        if !self._unknown_fields.is_empty() {
            for (key, value) in self._unknown_fields.iter() {
                state.serialize_entry(key, &value)?;
            }
        }
        state.end()
    }
}

#[doc(hidden)]
impl serde::ser::Serialize for super::condition_context::Peer {
    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
    where
        S: serde::ser::Serializer,
    {
        use serde::ser::SerializeMap;
        #[allow(unused_imports)]
        use std::option::Option::Some;
        let mut state = serializer.serialize_map(std::option::Option::None)?;
        if !self.ip.is_empty() {
            state.serialize_entry("ip", &self.ip)?;
        }
        if !wkt::internal::is_default(&self.port) {
            struct __With<'a>(&'a i64);
            impl<'a> serde::ser::Serialize for __With<'a> {
                fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
                where
                    S: serde::ser::Serializer,
                {
                    serde_with::As::<wkt::internal::I64>::serialize(self.0, serializer)
                }
            }
            state.serialize_entry("port", &__With(&self.port))?;
        }
        if !self._unknown_fields.is_empty() {
            for (key, value) in self._unknown_fields.iter() {
                state.serialize_entry(key, &value)?;
            }
        }
        state.end()
    }
}

#[doc(hidden)]
impl serde::ser::Serialize for super::condition_context::Request {
    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
    where
        S: serde::ser::Serializer,
    {
        use serde::ser::SerializeMap;
        #[allow(unused_imports)]
        use std::option::Option::Some;
        let mut state = serializer.serialize_map(std::option::Option::None)?;
        if self.receive_time.is_some() {
            state.serialize_entry("receiveTime", &self.receive_time)?;
        }
        if !self._unknown_fields.is_empty() {
            for (key, value) in self._unknown_fields.iter() {
                state.serialize_entry(key, &value)?;
            }
        }
        state.end()
    }
}

#[doc(hidden)]
impl serde::ser::Serialize for super::condition_context::EffectiveTag {
    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
    where
        S: serde::ser::Serializer,
    {
        use serde::ser::SerializeMap;
        #[allow(unused_imports)]
        use std::option::Option::Some;
        let mut state = serializer.serialize_map(std::option::Option::None)?;
        if !self.tag_value.is_empty() {
            state.serialize_entry("tagValue", &self.tag_value)?;
        }
        if !self.namespaced_tag_value.is_empty() {
            state.serialize_entry("namespacedTagValue", &self.namespaced_tag_value)?;
        }
        if !self.tag_key.is_empty() {
            state.serialize_entry("tagKey", &self.tag_key)?;
        }
        if !self.namespaced_tag_key.is_empty() {
            state.serialize_entry("namespacedTagKey", &self.namespaced_tag_key)?;
        }
        if !self.tag_key_parent_name.is_empty() {
            state.serialize_entry("tagKeyParentName", &self.tag_key_parent_name)?;
        }
        if !wkt::internal::is_default(&self.inherited) {
            state.serialize_entry("inherited", &self.inherited)?;
        }
        if !self._unknown_fields.is_empty() {
            for (key, value) in self._unknown_fields.iter() {
                state.serialize_entry(key, &value)?;
            }
        }
        state.end()
    }
}

#[doc(hidden)]
impl serde::ser::Serialize for super::AllowPolicyExplanation {
    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
    where
        S: serde::ser::Serializer,
    {
        use serde::ser::SerializeMap;
        #[allow(unused_imports)]
        use std::option::Option::Some;
        let mut state = serializer.serialize_map(std::option::Option::None)?;
        if !wkt::internal::is_default(&self.allow_access_state) {
            state.serialize_entry("allowAccessState", &self.allow_access_state)?;
        }
        if !self.explained_policies.is_empty() {
            state.serialize_entry("explainedPolicies", &self.explained_policies)?;
        }
        if !wkt::internal::is_default(&self.relevance) {
            state.serialize_entry("relevance", &self.relevance)?;
        }
        if !self._unknown_fields.is_empty() {
            for (key, value) in self._unknown_fields.iter() {
                state.serialize_entry(key, &value)?;
            }
        }
        state.end()
    }
}

#[doc(hidden)]
impl serde::ser::Serialize for super::ExplainedAllowPolicy {
    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
    where
        S: serde::ser::Serializer,
    {
        use serde::ser::SerializeMap;
        #[allow(unused_imports)]
        use std::option::Option::Some;
        let mut state = serializer.serialize_map(std::option::Option::None)?;
        if !wkt::internal::is_default(&self.allow_access_state) {
            state.serialize_entry("allowAccessState", &self.allow_access_state)?;
        }
        if !self.full_resource_name.is_empty() {
            state.serialize_entry("fullResourceName", &self.full_resource_name)?;
        }
        if !self.binding_explanations.is_empty() {
            state.serialize_entry("bindingExplanations", &self.binding_explanations)?;
        }
        if !wkt::internal::is_default(&self.relevance) {
            state.serialize_entry("relevance", &self.relevance)?;
        }
        if self.policy.is_some() {
            state.serialize_entry("policy", &self.policy)?;
        }
        if !self._unknown_fields.is_empty() {
            for (key, value) in self._unknown_fields.iter() {
                state.serialize_entry(key, &value)?;
            }
        }
        state.end()
    }
}

#[doc(hidden)]
impl serde::ser::Serialize for super::AllowBindingExplanation {
    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
    where
        S: serde::ser::Serializer,
    {
        use serde::ser::SerializeMap;
        #[allow(unused_imports)]
        use std::option::Option::Some;
        let mut state = serializer.serialize_map(std::option::Option::None)?;
        if !wkt::internal::is_default(&self.allow_access_state) {
            state.serialize_entry("allowAccessState", &self.allow_access_state)?;
        }
        if !self.role.is_empty() {
            state.serialize_entry("role", &self.role)?;
        }
        if !wkt::internal::is_default(&self.role_permission) {
            state.serialize_entry("rolePermission", &self.role_permission)?;
        }
        if !wkt::internal::is_default(&self.role_permission_relevance) {
            state.serialize_entry("rolePermissionRelevance", &self.role_permission_relevance)?;
        }
        if self.combined_membership.is_some() {
            state.serialize_entry("combinedMembership", &self.combined_membership)?;
        }
        if !self.memberships.is_empty() {
            state.serialize_entry("memberships", &self.memberships)?;
        }
        if !wkt::internal::is_default(&self.relevance) {
            state.serialize_entry("relevance", &self.relevance)?;
        }
        if self.condition.is_some() {
            state.serialize_entry("condition", &self.condition)?;
        }
        if self.condition_explanation.is_some() {
            state.serialize_entry("conditionExplanation", &self.condition_explanation)?;
        }
        if !self._unknown_fields.is_empty() {
            for (key, value) in self._unknown_fields.iter() {
                state.serialize_entry(key, &value)?;
            }
        }
        state.end()
    }
}

#[doc(hidden)]
impl serde::ser::Serialize for super::allow_binding_explanation::AnnotatedAllowMembership {
    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
    where
        S: serde::ser::Serializer,
    {
        use serde::ser::SerializeMap;
        #[allow(unused_imports)]
        use std::option::Option::Some;
        let mut state = serializer.serialize_map(std::option::Option::None)?;
        if !wkt::internal::is_default(&self.membership) {
            state.serialize_entry("membership", &self.membership)?;
        }
        if !wkt::internal::is_default(&self.relevance) {
            state.serialize_entry("relevance", &self.relevance)?;
        }
        if !self._unknown_fields.is_empty() {
            for (key, value) in self._unknown_fields.iter() {
                state.serialize_entry(key, &value)?;
            }
        }
        state.end()
    }
}

#[doc(hidden)]
impl serde::ser::Serialize for super::DenyPolicyExplanation {
    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
    where
        S: serde::ser::Serializer,
    {
        use serde::ser::SerializeMap;
        #[allow(unused_imports)]
        use std::option::Option::Some;
        let mut state = serializer.serialize_map(std::option::Option::None)?;
        if !wkt::internal::is_default(&self.deny_access_state) {
            state.serialize_entry("denyAccessState", &self.deny_access_state)?;
        }
        if !self.explained_resources.is_empty() {
            state.serialize_entry("explainedResources", &self.explained_resources)?;
        }
        if !wkt::internal::is_default(&self.relevance) {
            state.serialize_entry("relevance", &self.relevance)?;
        }
        if !wkt::internal::is_default(&self.permission_deniable) {
            state.serialize_entry("permissionDeniable", &self.permission_deniable)?;
        }
        if !self._unknown_fields.is_empty() {
            for (key, value) in self._unknown_fields.iter() {
                state.serialize_entry(key, &value)?;
            }
        }
        state.end()
    }
}

#[doc(hidden)]
impl serde::ser::Serialize for super::ExplainedDenyResource {
    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
    where
        S: serde::ser::Serializer,
    {
        use serde::ser::SerializeMap;
        #[allow(unused_imports)]
        use std::option::Option::Some;
        let mut state = serializer.serialize_map(std::option::Option::None)?;
        if !wkt::internal::is_default(&self.deny_access_state) {
            state.serialize_entry("denyAccessState", &self.deny_access_state)?;
        }
        if !self.full_resource_name.is_empty() {
            state.serialize_entry("fullResourceName", &self.full_resource_name)?;
        }
        if !self.explained_policies.is_empty() {
            state.serialize_entry("explainedPolicies", &self.explained_policies)?;
        }
        if !wkt::internal::is_default(&self.relevance) {
            state.serialize_entry("relevance", &self.relevance)?;
        }
        if !self._unknown_fields.is_empty() {
            for (key, value) in self._unknown_fields.iter() {
                state.serialize_entry(key, &value)?;
            }
        }
        state.end()
    }
}

#[doc(hidden)]
impl serde::ser::Serialize for super::ExplainedDenyPolicy {
    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
    where
        S: serde::ser::Serializer,
    {
        use serde::ser::SerializeMap;
        #[allow(unused_imports)]
        use std::option::Option::Some;
        let mut state = serializer.serialize_map(std::option::Option::None)?;
        if !wkt::internal::is_default(&self.deny_access_state) {
            state.serialize_entry("denyAccessState", &self.deny_access_state)?;
        }
        if self.policy.is_some() {
            state.serialize_entry("policy", &self.policy)?;
        }
        if !self.rule_explanations.is_empty() {
            state.serialize_entry("ruleExplanations", &self.rule_explanations)?;
        }
        if !wkt::internal::is_default(&self.relevance) {
            state.serialize_entry("relevance", &self.relevance)?;
        }
        if !self._unknown_fields.is_empty() {
            for (key, value) in self._unknown_fields.iter() {
                state.serialize_entry(key, &value)?;
            }
        }
        state.end()
    }
}

#[doc(hidden)]
impl serde::ser::Serialize for super::DenyRuleExplanation {
    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
    where
        S: serde::ser::Serializer,
    {
        use serde::ser::SerializeMap;
        #[allow(unused_imports)]
        use std::option::Option::Some;
        let mut state = serializer.serialize_map(std::option::Option::None)?;
        if !wkt::internal::is_default(&self.deny_access_state) {
            state.serialize_entry("denyAccessState", &self.deny_access_state)?;
        }
        if self.combined_denied_permission.is_some() {
            state.serialize_entry("combinedDeniedPermission", &self.combined_denied_permission)?;
        }
        if !self.denied_permissions.is_empty() {
            state.serialize_entry("deniedPermissions", &self.denied_permissions)?;
        }
        if self.combined_exception_permission.is_some() {
            state.serialize_entry(
                "combinedExceptionPermission",
                &self.combined_exception_permission,
            )?;
        }
        if !self.exception_permissions.is_empty() {
            state.serialize_entry("exceptionPermissions", &self.exception_permissions)?;
        }
        if self.combined_denied_principal.is_some() {
            state.serialize_entry("combinedDeniedPrincipal", &self.combined_denied_principal)?;
        }
        if !self.denied_principals.is_empty() {
            state.serialize_entry("deniedPrincipals", &self.denied_principals)?;
        }
        if self.combined_exception_principal.is_some() {
            state.serialize_entry(
                "combinedExceptionPrincipal",
                &self.combined_exception_principal,
            )?;
        }
        if !self.exception_principals.is_empty() {
            state.serialize_entry("exceptionPrincipals", &self.exception_principals)?;
        }
        if !wkt::internal::is_default(&self.relevance) {
            state.serialize_entry("relevance", &self.relevance)?;
        }
        if self.condition.is_some() {
            state.serialize_entry("condition", &self.condition)?;
        }
        if self.condition_explanation.is_some() {
            state.serialize_entry("conditionExplanation", &self.condition_explanation)?;
        }
        if !self._unknown_fields.is_empty() {
            for (key, value) in self._unknown_fields.iter() {
                state.serialize_entry(key, &value)?;
            }
        }
        state.end()
    }
}

#[doc(hidden)]
impl serde::ser::Serialize for super::deny_rule_explanation::AnnotatedPermissionMatching {
    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
    where
        S: serde::ser::Serializer,
    {
        use serde::ser::SerializeMap;
        #[allow(unused_imports)]
        use std::option::Option::Some;
        let mut state = serializer.serialize_map(std::option::Option::None)?;
        if !wkt::internal::is_default(&self.permission_matching_state) {
            state.serialize_entry("permissionMatchingState", &self.permission_matching_state)?;
        }
        if !wkt::internal::is_default(&self.relevance) {
            state.serialize_entry("relevance", &self.relevance)?;
        }
        if !self._unknown_fields.is_empty() {
            for (key, value) in self._unknown_fields.iter() {
                state.serialize_entry(key, &value)?;
            }
        }
        state.end()
    }
}

#[doc(hidden)]
impl serde::ser::Serialize for super::deny_rule_explanation::AnnotatedDenyPrincipalMatching {
    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
    where
        S: serde::ser::Serializer,
    {
        use serde::ser::SerializeMap;
        #[allow(unused_imports)]
        use std::option::Option::Some;
        let mut state = serializer.serialize_map(std::option::Option::None)?;
        if !wkt::internal::is_default(&self.membership) {
            state.serialize_entry("membership", &self.membership)?;
        }
        if !wkt::internal::is_default(&self.relevance) {
            state.serialize_entry("relevance", &self.relevance)?;
        }
        if !self._unknown_fields.is_empty() {
            for (key, value) in self._unknown_fields.iter() {
                state.serialize_entry(key, &value)?;
            }
        }
        state.end()
    }
}

#[doc(hidden)]
impl serde::ser::Serialize for super::ConditionExplanation {
    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
    where
        S: serde::ser::Serializer,
    {
        use serde::ser::SerializeMap;
        #[allow(unused_imports)]
        use std::option::Option::Some;
        let mut state = serializer.serialize_map(std::option::Option::None)?;
        if self.value.is_some() {
            state.serialize_entry("value", &self.value)?;
        }
        if !self.errors.is_empty() {
            state.serialize_entry("errors", &self.errors)?;
        }
        if !self.evaluation_states.is_empty() {
            state.serialize_entry("evaluationStates", &self.evaluation_states)?;
        }
        if !self._unknown_fields.is_empty() {
            for (key, value) in self._unknown_fields.iter() {
                state.serialize_entry(key, &value)?;
            }
        }
        state.end()
    }
}

#[doc(hidden)]
impl serde::ser::Serialize for super::condition_explanation::EvaluationState {
    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
    where
        S: serde::ser::Serializer,
    {
        use serde::ser::SerializeMap;
        #[allow(unused_imports)]
        use std::option::Option::Some;
        let mut state = serializer.serialize_map(std::option::Option::None)?;
        if !wkt::internal::is_default(&self.start) {
            struct __With<'a>(&'a i32);
            impl<'a> serde::ser::Serialize for __With<'a> {
                fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
                where
                    S: serde::ser::Serializer,
                {
                    serde_with::As::<wkt::internal::I32>::serialize(self.0, serializer)
                }
            }
            state.serialize_entry("start", &__With(&self.start))?;
        }
        if !wkt::internal::is_default(&self.end) {
            struct __With<'a>(&'a i32);
            impl<'a> serde::ser::Serialize for __With<'a> {
                fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
                where
                    S: serde::ser::Serializer,
                {
                    serde_with::As::<wkt::internal::I32>::serialize(self.0, serializer)
                }
            }
            state.serialize_entry("end", &__With(&self.end))?;
        }
        if self.value.is_some() {
            state.serialize_entry("value", &self.value)?;
        }
        if !self.errors.is_empty() {
            state.serialize_entry("errors", &self.errors)?;
        }
        if !self._unknown_fields.is_empty() {
            for (key, value) in self._unknown_fields.iter() {
                state.serialize_entry(key, &value)?;
            }
        }
        state.end()
    }
}
